package iotwisp.school.device.entity;

import iotwisp.base.orm.StringIdBaseEntity;
import iotwisp.school.area.entity.Area;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import javax.persistence.*;

@SuppressWarnings("serial")
@Data
@EqualsAndHashCode(callSuper = false)
@DynamicUpdate
@DynamicInsert
@Entity
@Table(name = M.TABLE_PREFIX + "device")
@Inheritance(strategy = InheritanceType.JOINED)
public class Device extends StringIdBaseEntity {

    /**
     * 设备所在区域
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "area_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Area area;

    /**
     * 设备编号
     */
    @Column(name = "code", length = 64)
    private String code;

    /**
     * 名称
     */
    @Column(name = "name", length = 64)
    private String name;

    /**
     * 描述
     */
    @Column(name = "description", length = 256)
    private String description;

    /**
     * 是否在线（通电）
     */
    @Type(type = "yes_no")
    @Column(name = "is_online")
    private Boolean online;

    /**
     * 是否已开启
     */
    @Type(type = "yes_no")
    @Column(name = "is_open")
    private Boolean open;

}
